﻿
/**
 * Masque Ajax Library 0.0.3.5
 * Copyright(c) 2008, 青岛领创网络科技有限公司
 * @author Lookingon Team
 */
if (window.LAjax) 
    var _LAjax = window.LAjax;

var LAjax = window.LAjax = {
    getTransport: function(){
        return Try.these(function(){
            return new XMLHttpRequest()
        }, function(){
            return new ActiveXObject('Msxml2.XMLHTTP')
        }, function(){
            return new ActiveXObject('Microsoft.XMLHTTP')
        }) ||
        false;
    },
    me: this,
    activeRequestCount: 0
};

LAjax.randomUrl = function(_Url){
    if (Masque.V.isString(_Url) && _Url != "") {
        if (_Url.indexOf("?") != -1) {
            _Url = _Url + "&" + Math.random();
        }
        else {
            _Url = _Url + "?" + Math.random();
        }
    }
    return _Url;
}

LAjax.InnerHTML = function(Container, URL, Tip){
    if (typeof(Container) != "object" || typeof(URL) != "string") 
        return;
    
    Container.innerHTML = (typeof(Tip) == "string" ? Tip : "<span style='color:red'>数据获取中请稍候......</span>");
    var xmlhttp = LAjax.getTransport();
    xmlhttp.open("Get", URL, true,null,null);
    xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4) {
            Container.innerHTML = xmlhttp.responseText;
        }
    }
    xmlhttp.send(null);
}

LAjax.GetText = function(_URL, _callBack){
    if (typeof(_URL) != "string") 
        return "";
    
    var xmlhttp = LAjax.getTransport();
    xmlhttp.open("Get", _URL, true,null,null);
    xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4) {
            if (Masque.V.isFunction(_callBack))
            {
                _callBack(xmlhttp.responseText);
                xmlhttp = null;

            }
        }
    }
    xmlhttp.send(null);
}


LAjax.Post = function(_URL, _callBack,_params,_transfer) {
    if (typeof(_URL) != "string") 
        return "";
    
    var xmlhttp = LAjax.getTransport();
    xmlhttp.onreadystatechange = function(){
    if (xmlhttp.readyState == 4) {
            _callBack(xmlhttp,_transfer);
        }
    }
	xmlhttp.open('POST', _URL, true);
	xmlhttp.setRequestHeader("content-length",_params.length); 
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	//xmlhttp.setRequestHeader("Connection", "close"); //这个东西在IE6下readyState状态永远到不了4
	xmlhttp.send(_params);
}




